#include<iostream>
using namespace std;
#include<vector>
class Solution {
public:
    int countPrimes(int n) {
        vector<int> vec(n, 0);
        int ans = 0;
        for (long long i = 2; i < n; ++i) {
            if (vec[i] == 0) {
                ++ans;
                for (long long j = i * i; j < n; j += i)
                    vec[j] = 1;
            }
        }
        return ans;
    }
};